#pragma once

#include <wx/wx.h>
#include <wx/hashmap.h>
#include <wx/wxsqlite3.h>
#include <wx/filename.h>
#include <wx/wxhtml.h>
#include <wx/listctrl.h>

class DictQuery;

/**
 * Theme dir hash map
 */
WX_DECLARE_STRING_HASH_MAP(DictQuery*, DictQueryHash);


class DictManager {
public:
    virtual ~DictManager();

    static DictManager& get() {
        if(_dict_mgr==NULL) {
            _dict_mgr = new DictManager();
        }

        return *_dict_mgr;
    }

    // wxString get_all_u
    bool install_dicts(const wxString& zippath);
	bool install_dict(const wxString& filename);
	bool uninstall_dict(const wxString& filename);
    
    void reinit_installed_dict_info();
	
	bool disable_dict(const wxString& filename);
	bool enable_dict(const wxString& filename);
	
	bool swap_dicts_order(const wxString& filename1, const int order1, \
			const wxString& filename2, const int order2);
	
	bool append_words_to_listctrl(const wxString& word, wxListView* listctrl);
	bool show_word_dicts(const wxString& word, wxListView* listctrl, wxHtmlWindow* explain_wnd);
	bool show_dict_explain(wxListView* listctrl, int listindex, wxHtmlWindow* explain_wnd);
	
    bool maintains_mgrdb();
    
	bool create_all_dicts_dbconn(); // you must create conns, after add/remove/enable/disable dicts
	bool delete_all_dicts_dbconn(); // you must delete conns, before add/remove/enable/disable dicts
    
	DictQuery* get_dictquery(const wxString& filename) {
		return _dict_query_hash[filename];
	}
    
    /** Get global dict directory
     * Example return values: 
     *   Unix: prefix/share/Daodict/dict
     *   Windows: the directory where the executable file is located\dict
     *   Mac: Daodict.app/Contents/SharedSupport bundle/dict
     */
    wxFileName dict_dir;

    
	// infos
    int installed_dict_count;
    wxArrayString installed_dict_names;
    wxArrayString installed_dict_filenames;
    wxArrayInt installed_dict_status;
    wxArrayInt installed_dict_xorder;


protected :
	wxFileName _dictmgr_db_fn;
	wxString _current_word;
	
	wxSQLite3Database _dictmgr_db;
    
    DictQueryHash _dict_query_hash;
	
    static DictManager* _dict_mgr;

private :
    DictManager();
};
